﻿namespace MemoryTest_Communications.PropertySearch
{
    using System;
    using Model;
    using WP7Contrib.Common;

    public sealed class SearchCriteria : BaseModel, IEquatable<SearchCriteria>
    {
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public PropertyCriteria Criteria { get; private set; }

        public SearchCriteria()
        {
        }

        public SearchCriteria(int pageIndex, int pageSize, PropertyCriteria criteria)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            Criteria = criteria;
        }

        public static bool operator ==(SearchCriteria sc1, SearchCriteria sc2)
        {
            return Equals(sc1, sc2);
        }

        public static bool operator !=(SearchCriteria sc1, SearchCriteria sc2)
        {
            return !Equals(sc1, sc2);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            return obj is SearchCriteria && this.Equals((SearchCriteria)obj);
        }

        public override int GetHashCode()
        {
            return this.CombineHashCodes(new object[] { this.PageIndex, this.PageSize, this.Criteria });
        }

        public bool Equals(SearchCriteria searchCriteria)
        {
            if (ReferenceEquals(null, searchCriteria))
            {
                return false;
            }

            if (this.PageIndex != searchCriteria.PageIndex)
                return false;

            if (this.PageSize != searchCriteria.PageSize)
                return false;

            if (this.Criteria != searchCriteria.Criteria)
                return false;

            return true;
        }
    }
}